<?php
  function do_post_request($url, $data, $optional_headers = null)
  {
     $params = array('http' => array(
                  'method' => 'GET',
                  'content' => $data
               ));
     if ($optional_headers !== null) {
        $params['http']['header'] = $optional_headers;
     }
     $ctx = stream_context_create($params);
     $fp = @fopen($url, 'rb', false, $ctx);
     if (!$fp) {
        throw new Exception("Problem with $url, $php_errormsg");
     }
     $response = @stream_get_contents($fp);
     if ($response === false) {
        throw new Exception("Problem reading data from $url, $php_errormsg");
     }
     return $response;
  }
  
  if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
    // Read the input from stdin     
    //print_r("[".file_get_contents("php://input")."]");
    $username = $_POST['username'];
    $password = $_POST['secpassword'];       
  }
  else {
    $place =  $_GET['place'];       
  }
  
  if($place) {
    $url = "http://maps.google.com/maps/geo?q=".urlencode($place)."&output=csv&key=ABQIAAAA6cs7716kYs3Ko1SvfMt_exQXdHDrzlCyUW1cOQLk9qowMRLGdxT4IMJUue67Jy2jbNedZmC-wzC96g"; 
    $result = do_post_request($url,"");
  }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title><?php echo $product_name;?></title>
  </head>
  <body>
  <form action="geoSearch.php">
    <input type="text" name="place"></input>
    <input type="submit" value="search"></input>
  </form>
  <p>
  <?php
    echo $result;
  ?>
  </p>
  </body>
</html>